var productIntroduce = {
  swiper: function() {
    //轮播插件
    //  var this=that;
    var mySwiper = new Swiper('.swiper-container', {
      autoplay: 3000, //可选选项，自动滑动
      pagination: '.swiper-pagination',
      paginationElement: 'span',
      autoplayDisableOnInteraction: false,
      callback: function() {}
    })
  },
  scrollToElement: function(ele, speed) {
    if(!speed) speed = 300;
    if($("#scheduling").height() + $("#ticketInfo").height() + 2 * $("#barBox").height() < document.documentElement.clientHeight && ele == "#scheduling") {
      $("html,body").animate({
        scrollTop: 0
      }, speed);
    } else {
      $("html,body").animate({
        scrollTop: $(ele).offset().top - $("#barBox").height() + 3
      }, speed);
    }
    return false;
  },
  isHidden: function(ele, btnEle, className, distance) {
    //是否隐藏
    if(ele.height() > distance) {
      ele.addClass(className)
      btnEle.removeClass("hidden")
    }
  },
  loadMore: function(btnEle, ele, className) {
    //查看更多
    btnEle.on("click", function() {
      ele.toggleClass(className)
      if(ele.hasClass(className)) {
        btnEle.html("显示更多")
        if(className == 'features-conceal') {
          $("html,body").animate({
            scrollTop: 0
          }, 300);
        } else {
          $("html,body").animate({
            scrollTop: $(ele).offset().top - $("#barBox").height()
          }, 300);
        }

      } else {
        btnEle.html("立即收起")
      }
    })
  },
  getInfo: function() {
    //获得数据
    var that = this;
    var param = {
      templateId: common.getUrlParams("templateId")
    }
    console.log(param)
    common.get({
      url: "/productDetails.shtml",
      data: param,
      callback: function(result) {
        if(result.code == 200) {
          if(result.data) {
            var expressContent = JSON.parse(result.data.expressContent)
            var bannerData = JSON.parse(result.data.expressBanner)
            $("#bannerSrc").tmpl(bannerData).appendTo('#banners')
            $("#titleInfo").tmpl(result.data).appendTo('#titleBox')
            $(".features-content").html(expressContent.advantage)
            $(".scheduling-content").html(expressContent.scheduling)
            $(".ticket-info-content").html(expressContent.notice)
            $(".childStandard-content").html(expressContent.childStandard)
          }
          that.swiper();
          that.init();
        }
      }
    });
  },
  init: function() {
    //初始化
    var that = this;
    this.isHidden($("#scheduling"), $("#showScheduling"), "scheduling-conceal", 300)
    this.isHidden($("#features"), $("#showFeatures"), "features-conceal", 300)
    this.isHidden($("#ticketInfo"), $("#showNotice"), "ticket-info-conceal", 300)
    this.loadMore($("#showNotice"), $("#ticketInfo"), "ticket-info-conceal")
    this.loadMore($("#showScheduling"), $("#scheduling"), "scheduling-conceal")
    this.loadMore($("#showFeatures"), $("#features"), "features-conceal")
    $(window).scroll(function() {
      //滚动条事件
      if($("#scheduling").height() + $("#ticketInfo").height() + 2 * $("#barBox").height() >= document.documentElement.clientHeight) {
        if($("#barBox").offset().top - $("#containerBox").scrollTop() < 0) {
          $("#barBox").addClass("position-bar")
        }
        if($("#scheduling").offset().top - $("#containerBox").scrollTop() > $("#barBox").height() - 5) {
          $("#barBox").removeClass("position-bar");
          $(".bar-item").removeClass("active")
          $("#routing").addClass("active");
        }
      } else {
        $(".bar-item").removeClass("active")
        $("#routing").addClass("active");
      }
      if(($("#ticketInfo").offset().top - $("#barBox").height()) - $("#containerBox").scrollTop() <= 0) {
        $(".bar-item").removeClass("active")
        $("#buyTicketInfo").addClass("active");
      }
      if($(this).scrollTop() + $(this).height() == $(document).height()) {
        $(".bar-item").removeClass("active")
        $("#buyTicketInfo").addClass("active");
      }
    })
    $(".img-item").height(document.documentElement.clientWidth/375*150)
    $(".bar-item").on("click", function() {
      //tab切换
      that.scrollToElement('#' + $(this).attr("anchor"), 300)
    })
  },
}
productIntroduce.getInfo();